<?php
	include "layout.php";
	
	head("Deposits");
?>
<h1>List of Deposits</h1>
<h2>Ordered By Date Found</h2>
<?php
	if (!isset($_GET["page"])) {
		$page = 1;
	}
	else {
		$page = $_GET["page"];
	}
	$lower = ($page - 1)*20;
	$upper = $page*20;
	$next = $page + 1;
	$prev = $page - 1;
	echo "<table border=1>";
	echo "<tr>";
	echo "<th>Raw Material</th>";
	echo "<th>Deposit Size</th>";
	echo "<th>Planet</th>";
	echo "<th>Terrain</th>";
	echo "<th>Coordinates</th>";
	echo "<th>Date Found</th>";
	echo "<th></th>";
	echo "</tr>";
	$query = mysql_query("SELECT * FROM deposits ORDER BY date LIMIT {$lower},{$upper}");
	$entries = mysql_num_rows($query);
	while ($results = mysql_fetch_array($query)) {
		$planets = mysql_query("SELECT * FROM planets WHERE id={$results["planet"]}");
		$planet = mysql_fetch_array($planets);
		$rmtypes = mysql_query("SELECT * FROM rmtypes WHERE id={$results["rmtype"]}");
		$rmtype = mysql_fetch_array($rmtypes);
		$terrains = mysql_query("SELECT * FROM terrain WHERE id={$results["terrain"]}");
		$terrain = mysql_fetch_array($terrains);
		echo "<tr>";
		echo "<td style='text-align:left'>{$rmtype["name"]}</td>";
		echo "<td style='text-align:left'>{$results["value"]}</td>";
		echo "<td style='text-align:left'><a href='planet.php?id={$planet["id"]}'>{$planet["name"]}</a></td>";
		echo "<td style='text-align:left'>{$terrain["name"]}</td>";
		echo "<td>{$results["x"]},{$results["y"]}</td>";
		echo "<td>{$results["date"]}</td>";
		echo "<td><a href='editdeposit.php?id={$results["id"]}'>Edit?</a><br />";
		//echo "<td><a href='#' title='Feature Currently Unavailable'>Edit?</a><br />";
		echo "<a href='deletedeposit.php?id={$results["id"]}'>Delete?</a></td>";
		//echo "<a href='#' title='Feature Currently Unavailable'>Delete?</a></td>";
		echo "</tr>";
	}
	echo "<tr>";
	echo "<td colspan=7><a href='adddeposit.php'>Create a New Deposit</a></td>";
	echo "</tr>";
	if ($page > 1 || $entries == 20) {
		echo "<tr>";
		if ($page > 1) {
			echo "<td colspan=3><a href='deposits.php?page={$prev}'>Previous Page</a></td>";
		}
		else {
			echo "<td colspan=3></td>";
		}
		echo "<td></td>";
		if ($entries < 20) {
			echo"<td colspan=3></td>";
		}
		else {
			echo"<td colspan=3><a href='deposits.php?page={$next}'>Next Page</a></td>";
		}
		echo "</tr>";
	}
	echo "</table>";
?>
<?php
	foot();
?>